package com.example.no1admin.controller;

import com.example.no1admin.pojo.dto.style.StyleAddNewDTO;
import com.example.no1admin.pojo.dto.style.StyleEditDTO;
import com.example.no1admin.pojo.vo.style.StyleListItemVO;
import com.example.no1admin.service.IStyleService;
import com.example.no1admin.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "拍摄风格管理模块")
@RequestMapping("/styles")
@Slf4j
@RestController
public class StyleController {
    @Autowired
    IStyleService styleService;

    @ApiOperation("拍摄风格")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody StyleAddNewDTO styleAddNewDTO){
        log.debug("接受到的请求参数:{}",styleAddNewDTO);
        styleService.addNew(styleAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除拍摄风格")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult deleteById(@PathVariable Long id){
        log.debug("接收到删除拍摄风格的请求");
        styleService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改拍摄风格")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update")
    public JsonResult updateById(@RequestBody StyleEditDTO styleEditDTO){
        log.debug("接收到修改拍摄风格的请求{}",styleEditDTO);
        styleService.updateById(styleEditDTO);
        return JsonResult.ok();
    }

    @ApiOperation("拍摄风格列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult list(){
        log.debug("接收到查询拍摄风格列表的请求");
        List<StyleListItemVO> styles = styleService.list();
        return JsonResult.ok(styles);
    }
}
